<template>
  <div style="display:inline">
    <a-button
      type="primary"
      icon="vertical-align-top"
      @click="onImportData"
    >导入采购商品</a-button>
    <import-excel
      ref="import"
      @onImportData="onSubmitExcel"
    >
      <!-- <template #cusBtn>
            <export-excel ref="export" btnType="default" btnText="下载模板" @getExcelData="onDownloadDemo"></export-excel>
        </template> -->
    </import-excel>
  </div>
</template>

<script>
import importExcel from '@/views/app/biz/common/importExcel'
import exportExcel from '@/views/app/biz/common/exportExcel/index.vue'
import { fileUpload } from './upload'
export default {
  name: 'importGoodsModal',
  components: {
    importExcel,
    exportExcel
  },
  data () {
    return {}
  },
  methods: {
    onDownloadDemo () {
      //x下载模板，如需请求数据，则在此请求数据后执行以下
      this.$emit('onDownloadDemo')
      let listName = '基础商品信息'
      let listHeader = [
        '商品自编码',
        '商品名称',
        '一级分类（学科、品类）',
        '二级分类（用途、品目）',
        '三级分类（部位、功能、品种）',
        '品牌'
      ]
      let listField = ['code', 'productNameZh', 'first', 'second', 'third', 'brand']
      let exportList = []
      this.$refs.export.setData(listName, listHeader, listField, exportList)
    },
    onImportData () {
      //导入excel预览列表的columns,要求title值和excel表头值一一对应
      const excelColumns = [
        { title: '唯一标识', dataIndex: 'pid', key: 'pid', view: false, require: true, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '编码', dataIndex: 'standardCode', key: 'standardCode', view: true, require: true, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '品名', dataIndex: 'productNameZh', key: 'productNameZh', view: true, require: true, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '通用名', dataIndex: 'commonName', key: 'commonName', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '规格', dataIndex: 'spec', key: 'spec', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '型号', dataIndex: 'model', key: 'model', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '计量单位', dataIndex: 'measurement', key: 'measurement', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '生产企业中文名称', dataIndex: 'manufacturerZh', key: 'manufacturerZh', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '供应商名称', dataIndex: 'supplierName', key: 'supplierName', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '供应商编码', dataIndex: 'supplierOrgCode', key: 'supplierOrgCode', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '注册证类型', dataIndex: 'approvalType', key: 'approvalType', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '注册证号', dataIndex: 'approvalNum', key: 'approvalNum', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '结算方式', dataIndex: 'settlementType', key: 'settlementType', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '价格(元)', dataIndex: 'iunitprice', key: 'iunitprice', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '集采号', dataIndex: 'acquisitionCode', key: 'acquisitionCode', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
        { title: '数量', dataIndex: 'num', key: 'num', view: true, require: false, align: 'center', scopedSlots: { customRender: 'unfilled' } },
      ]
      this.$refs.import.showModal(excelColumns)
    },
    //提交导入数据
    async onSubmitExcel (val) {
      this.$emit('onSubmitData', val)
      this.$refs.import.closeModal2()

      //执行提交数据代码，提交成功后执行this.$refs.import.closeModal2()
      // let key = 'updatable'
      // this.$message.loading({ content: '导入中', key })
      // let res = await fileUpload(val, {})
      // console.log(res)
      // if (res && res.code && res.code === 'C1' && res.data) {
      //   this.$message.success({ content: '导入成功', key, duration: 3 })
      //   this.$refs.import.closeModal2()
      //   this.$confirm({
      //     title: '导入完成',
      //     content: '成功：'+res.data.insert+' 条；\n更新：'+res.data.update+' 条；\n错误：'+res.data.error+' 条',
      //     onOk() {},
      //     onCancel() {},
      //   });
      // } else {
      //   this.$message.success({ content: '导入失败，请稍后重试', key, duration: 2 })
      // }
    }
  }
}
</script>

<style></style>
